﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class basketCollierCheck : MonoBehaviour {

	public Image guidebg = null;
	public Transform guide = null;
	public Transform btnLeft = null;
	public Transform btnRight = null;




	// Use this for initialization
	void Awake () {
		sguideBg = guidebg;
		sguideEle = guide.gameObject;

		CloseGuide ();
	}
	
	// Update is called once per frame
	void Update () {
		
	}


	public static GameObject nowStaffLeft = null;
	public static GameObject nowStaffRight = null;
	void OnTriggerEnter2D(Collider2D collider)
	{

		if (collider.gameObject.name == "staffLeft") {

			nowStaffLeft = collider.gameObject;
			if (collider.gameObject.tag == "firstLeft") {

				// guide
				guidebg.enabled = true;
				guide.gameObject.SetActive(true);
				guide.localPosition = btnLeft.localPosition + new Vector3(170,170,0);

				collider.gameObject.tag = "Untagged";

				BaseGame.nowGame.Pause ();
			}
				
		}

		else if (collider.gameObject.name == "staffRight") {

			nowStaffRight = collider.gameObject;
			if (collider.gameObject.tag == "firstRight") {

				// guide
				guidebg.enabled = true;
				guide.gameObject.SetActive(true);
				guide.localPosition = btnRight.localPosition + new Vector3(-170,170,0);
				Time.timeScale = 0;

				collider.gameObject.tag = "Untagged";

				BaseGame.nowGame.Pause ();

			}
				
		}

	}






	void OnTriggerExit2D(Collider2D collider)
	{

		if (collider.gameObject.name == "staffLeft") {

            if (collider.gameObject == nowStaffLeft)
                nowStaffLeft = null;

		}

		else if (collider.gameObject.name == "staffRight") {

            if ( collider.gameObject == nowStaffRight )
			    nowStaffRight = null;

        }

		if (collider.gameObject.tag == "lastGudian") {

			// finish
			SceneCreator2.GetInstance().FinishGame();

			Debug.Log ("finish");

		}


	}

	private static Image sguideBg = null;
	private static GameObject sguideEle = null;
	public static void CloseGuide()
	{

			sguideBg.enabled = false;
			sguideEle.SetActive (false);



	}
		

}
